package com.yellowpage.bigdata.service;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.yellowpage.white.common.Constants;
import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;

import com.yellowpage.bigdata.data.NspOnofflogTaImeiMonthEntity;
import com.yellowpage.bigdata.dao.NspOnofflogTaImeiMonthEntityDao;

public class NspOnofflogTaImeiMonthEntityServiceImpl extends BaseServiceImpl implements NspOnofflogTaImeiMonthEntityService {
    private NspOnofflogTaImeiMonthEntityDao nspOnofflogTaImeiMonthEntityDao;

    public void setNspOnofflogTaImeiMonthEntityDao(NspOnofflogTaImeiMonthEntityDao nspOnofflogTaImeiMonthEntityDao) {
        this.nspOnofflogTaImeiMonthEntityDao = nspOnofflogTaImeiMonthEntityDao;
    }


    /* Smooth generate Method */
    public NspOnofflogTaImeiMonthEntity getNspOnofflogTaImeiMonthEntity(Long id) {
        return nspOnofflogTaImeiMonthEntityDao.get(id);
    }

    public List<NspOnofflogTaImeiMonthEntity> getAllNspOnofflogTaImeiMonthEntity() {
        return nspOnofflogTaImeiMonthEntityDao.getAll();
    }

    public List<Map> queryNspOnofflogTaImeiMonthEntityByPage(Map queryMap, PageRender pageRender) {

        QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(
                "SELECT a.UV_IMEI , a.AREACODE , a.MONTH_ID , a.ETL_TIME , a.CREATE_USER , a.NOTE , a.OPT , a.CHANNELNO , a.NSP_ONOFFLOG_TA_IMEI_ID    FROM NSP_ONOFFLOG_TA_IMEI_MONTH a WHERE 1=1 ")
                .addCondition(" and MONTH_ID = :monthId ");


        List<Map> resultList = sqlAssistant.queryByPage(
                baseDao.getConnection(), queryMap, pageRender);

        return resultList;
    }


    public void saveNspOnofflogTaImeiMonthEntity(NspOnofflogTaImeiMonthEntity nspOnofflogTaImeiMonthEntity) {
        nspOnofflogTaImeiMonthEntityDao.save(nspOnofflogTaImeiMonthEntity);
    }

    public void updateNspOnofflogTaImeiMonthEntity(NspOnofflogTaImeiMonthEntity nspOnofflogTaImeiMonthEntity) {
        nspOnofflogTaImeiMonthEntityDao.update(nspOnofflogTaImeiMonthEntity);
    }

    public void delete(List deleteList) {
        nspOnofflogTaImeiMonthEntityDao.remove(deleteList);
    }

    @Override
    public List<Map> queryAllNspOnofflogTaImeiMonthEntityByMonth(Map queryMap) {
        String monthId = queryMap.get("query_monthId").equals("") ? "" : " and MONTH_ID = " + queryMap.get("query_monthId");
        String group = " group by NAME order by COUNT desc limit 10";
        QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(
                "SELECT  d.name as NAME, sum(a.UV_IMEI) as COUNT FROM OMC_DIC_TABLE d, NSP_ONOFFLOG_TA_IMEI_MONTH a WHERE d.VALUE = a.CHANNELNO and d.DIC_NAME='NSP_ONOFFLOG_CHANNEL_NO' and 1=1 " + monthId + group);
        List<Map> resultList = sqlAssistant.query(
                baseDao.getConnection(), queryMap);

        return resultList;
    }


}	